package controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.action.ActionMessages;

public class LoginAction extends Action {

	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		LoginActionForm loginForm = (LoginActionForm) form;
        if (loginForm.getUsername().equals("admin") && loginForm.getPassword().equals("admin")) {
            loginForm.setLogging(true);
        	return mapping.findForward("success");
        } else {
        	ActionMessages errors = new ActionMessages();
        	errors.add("username_err",
        	new ActionMessage("error.user.exist"));
        	saveErrors(request,errors);
            return mapping.getInputForward();
        }
	}

}
